package com.tnxst.phexamination.fragment.follow;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProviders;

import com.bigkoo.pickerview.TimePickerView;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.entity.LocalMedia;
import com.tnxst.phexamination.R;
import com.tnxst.phexamination.constant.HISConfig;
import com.tnxst.phexamination.databinding.FilingPhthisisBinding;
import com.tnxst.phexamination.dto.InhabitantDTO;
import com.tnxst.phexamination.dto.TbPatientRecordDTO;
import com.tnxst.phexamination.public_health_docking_interface.TuberculosisInterface;
import com.tnxst.phexamination.utils.PictureFileUtil;
import com.tnxst.phexamination.utils.StringUtils;
import com.tnxst.phexamination.utils.Utils;
import com.tnxst.phexamination.utils.WebServiceUtils;
import com.tnxst.phexamination.viewmodel.GlobalViewModel;

import org.apache.commons.collections.CollectionUtils;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class FilingPhthisisFragment extends Fragment {

    private FilingPhthisisBinding binding;

    private GlobalViewModel viewModel;

    private Context context;

    private InhabitantDTO inhabitantDTO;

    private boolean flag = false;

    private TbPatientRecordDTO tbPatientRecordDTO;

    //新增定位功能及拍照功能的控件
    private EditText address;

    private ImageView picture1;

    private ImageView picture2;

    private ImageView picture3;

    private Switch aSwitch;

    private Button start;

    private TextView del1;

    private TextView del2;

    private TextView del3;



    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        binding = DataBindingUtil.inflate(inflater, R.layout.filing_phthisis, container, false);
        context = container.getContext();
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        viewModel = ViewModelProviders.of(requireActivity()).get(GlobalViewModel.class);
        initData();
        initView();
        initAddress();
    }

    /**
     * 初始化视图
     */
    private void initView() {
        binding.editText2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String idCard = s.toString();
                if (idCard.length() >= 2 ){
                    List<InhabitantDTO> dtoList = viewModel.getInhabitantRepository().findByFieldList("NAME", idCard);
                    if (!CollectionUtils.isEmpty(dtoList)){
                        InhabitantDTO i = dtoList.get(0);
                        if (i != null){
                            inhabitantDTO = i;
//                            if (StringUtils.isNotNull(HISConfig.PRODUCT_CODE)){
//                                TuberculosisInterface.verifyIsTbPatient(inhabitantDTO.getID(), new WebServiceUtils.Response<Map>() {
//                                    @Override
//                                    public void onSuccess(Map result) {
//                                        String is = result.get("Msg").toString();
//                                        if ("1.0".equals(is)){
//                                            return;
//                                        }
//                                    }
//                                    @Override
//                                    public void onError(String error) {
//                                        Utils.Toast(context,"验证患者是否失败！\n失败原因：" + error);
//                                    }
//                                });
//                            }
                            setInhabitantView();
                        }else {
                            clearInhabitantView();
                        }
                    }else {
                        clearInhabitantView();
                        inhabitantDTO = null;
                    }
                }
            }
        });
        if (StringUtils.isNull(binding.textView23.getText().toString()))
            binding.textView23.setText(Utils.getTime(new Date()));
        binding.textView23.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TimePickerView pvTime = new TimePickerView.Builder(getActivity(), new TimePickerView.OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {
                        binding.textView23.setText(Utils.getTime(date));
                    }
                })
                        .setType(new boolean[]{true, true, true, false, false, false})
                        .setTitleText("登记时间")
                        .setTitleColor(Color.WHITE)//标题文字颜色
                        .setSubmitColor(Color.parseColor("#43c489"))
                        .setCancelColor(Color.parseColor("#43c489"))
                        .setTitleBgColor(Color.parseColor("#43c489"))
                        .setDividerColor(Color.parseColor("#43c489"))
                        .setTextColorCenter(Color.parseColor("#43c489"))
                        .setTitleSize(14)
                        .setContentSize(14)
                        .setSubCalSize(14)
                        .build();

                pvTime.setDate(Calendar.getInstance());//注：根据需求来决定是否使用该方法（一般是精确到秒的情况），此项可以在弹出选择器的时候重新设置当前时间，避免在初始化之后由于时间已经设定，导致选中时间与当前时间不匹配的问题。
                pvTime.show();
            }
        });

        if (StringUtils.isNull(binding.textView236.getText().toString()))
            binding.textView236.setText(Utils.getTime(new Date()));
        binding.textView236.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TimePickerView pvTime = new TimePickerView.Builder(getActivity(), new TimePickerView.OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {
                        binding.textView236.setText(Utils.getTime(date));
                    }
                })
                        .setType(new boolean[]{true, true, true, false, false, false})
                        .setTitleText("确诊时间")
                        .setTitleColor(Color.WHITE)//标题文字颜色
                        .setSubmitColor(Color.parseColor("#43c489"))
                        .setCancelColor(Color.parseColor("#43c489"))
                        .setTitleBgColor(Color.parseColor("#43c489"))
                        .setDividerColor(Color.parseColor("#43c489"))
                        .setTextColorCenter(Color.parseColor("#43c489"))
                        .setTitleSize(14)
                        .setContentSize(14)
                        .setSubCalSize(14)
                        .build();

                pvTime.setDate(Calendar.getInstance());//注：根据需求来决定是否使用该方法（一般是精确到秒的情况），此项可以在弹出选择器的时候重新设置当前时间，避免在初始化之后由于时间已经设定，导致选中时间与当前时间不匹配的问题。
                pvTime.show();
            }
        });

        if (StringUtils.isNull(binding.textView234.getText().toString()))
            binding.textView234.setText(Utils.getTime(new Date()));
        binding.textView234.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TimePickerView pvTime = new TimePickerView.Builder(getActivity(), new TimePickerView.OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {
                        binding.textView234.setText(Utils.getTime(date));
                    }
                })
                        .setType(new boolean[]{true, true, true, false, false, false})
                        .setTitleText("最近一次治疗日期")
                        .setTitleColor(Color.WHITE)//标题文字颜色
                        .setSubmitColor(Color.parseColor("#43c489"))
                        .setCancelColor(Color.parseColor("#43c489"))
                        .setTitleBgColor(Color.parseColor("#43c489"))
                        .setDividerColor(Color.parseColor("#43c489"))
                        .setTextColorCenter(Color.parseColor("#43c489"))
                        .setTitleSize(14)
                        .setContentSize(14)
                        .setSubCalSize(14)
                        .build();

                pvTime.setDate(Calendar.getInstance());//注：根据需求来决定是否使用该方法（一般是精确到秒的情况），此项可以在弹出选择器的时候重新设置当前时间，避免在初始化之后由于时间已经设定，导致选中时间与当前时间不匹配的问题。
                pvTime.show();
            }
        });

        if (StringUtils.isNull(binding.textView235.getText().toString()))
            binding.textView235.setText(Utils.getTime(new Date()));
        binding.textView235.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TimePickerView pvTime = new TimePickerView.Builder(getActivity(), new TimePickerView.OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {
                        binding.textView235.setText(Utils.getTime(date));
                    }
                })
                        .setType(new boolean[]{true, true, true, false, false, false})
                        .setTitleText("本次化疗开始日期")
                        .setTitleColor(Color.WHITE)//标题文字颜色
                        .setSubmitColor(Color.parseColor("#43c489"))
                        .setCancelColor(Color.parseColor("#43c489"))
                        .setTitleBgColor(Color.parseColor("#43c489"))
                        .setDividerColor(Color.parseColor("#43c489"))
                        .setTextColorCenter(Color.parseColor("#43c489"))
                        .setTitleSize(14)
                        .setContentSize(14)
                        .setSubCalSize(14)
                        .build();

                pvTime.setDate(Calendar.getInstance());//注：根据需求来决定是否使用该方法（一般是精确到秒的情况），此项可以在弹出选择器的时候重新设置当前时间，避免在初始化之后由于时间已经设定，导致选中时间与当前时间不匹配的问题。
                pvTime.show();
            }
        });
        binding.button34.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hideAddFragment();
            }
        });
        binding.button35.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tbPatientRecordDTO.setAddress(address.getText().toString());
                if (StringUtils.isNull(tbPatientRecordDTO.getAddress())
                        || (StringUtils.isNull(tbPatientRecordDTO.getPicturePath1())
                        && StringUtils.isNull(tbPatientRecordDTO.getPicturePath2())
                        && StringUtils.isNull(tbPatientRecordDTO.getPicturePath3()))){
                    Utils.Toast(context,"请完善地址信息或者拍摄现场图片后再保存！");
                    return;
                }
                if (inhabitantDTO == null){
                    Utils.Toast(context,"请完善病人信息！");
                    return;
                }

                if (flag){
                    Utils.Toast(context,"该患者已经建档！");
                    return;
                }
                save();
                tbPatientRecordDTO.setUpload(false);
                if (StringUtils.isNull(tbPatientRecordDTO.getTbId()))
                    tbPatientRecordDTO.setTbId(UUID.randomUUID().toString());
                viewModel.getTbPatientRecordRepository().insert(tbPatientRecordDTO);
                Utils.Toast(context,"保存本地成功！");
                hideAddFragment();
//                if (StringUtils.isNotNull(HISConfig.PRODUCT_CODE)){
//                    String oldId = tbPatientRecordDTO.getTbId();
//                    if (tbPatientRecordDTO.getTbId() != null && tbPatientRecordDTO.getTbId().endsWith("@"))
//                        tbPatientRecordDTO.setTbId(null);
//                    TuberculosisInterface.saveOrUpdateTbPatientRecord(tbPatientRecordDTO, viewModel.getUserInfo().getLoginVo().getOrgId(), new WebServiceUtils.Response<Map>() {
//                        @Override
//                        public void onSuccess(Map result) {
//                            if (result.get("ID") != null){
//                                String id = result.get("ID").toString();
//                                if (tbPatientRecordDTO.getTbId() == null){
//                                    if (StringUtils.isNotNull(oldId)){
//                                        tbPatientRecordDTO.setTbId(oldId);
//                                        viewModel.getTbPatientRecordRepository().delete(tbPatientRecordDTO);
//                                    }
//                                    tbPatientRecordDTO.setTbId(id);
//                                    viewModel.getTbPatientRecordRepository().insert(tbPatientRecordDTO);
//                                }
//                                Utils.Toast(context,"保存成功！");
//                            }else {
//                                viewModel.getTbPatientRecordRepository().insert(tbPatientRecordDTO);
//                                Utils.Toast(context,"修改成功！");
//                            }
//                            hideAddFragment();
//                        }
//                        @Override
//                        public void onError(String error) {
//                            Utils.Toast(context,"保存失败！\n失败原因：" + error);
//                        }
//                    });
//                }else {
//                    if (StringUtils.isNull(tbPatientRecordDTO.getTbId()))
//                        tbPatientRecordDTO.setTbId(UUID.randomUUID().toString() + "@");
//                    viewModel.getTbPatientRecordRepository().insert(tbPatientRecordDTO);
//                    Utils.Toast(context,"保存本地成功！");
//                    hideAddFragment();
//                }

            }
        });
    }

    private void initAddress() {
        address = binding.include.findViewById(R.id.editTextTextPersonName33);
        picture1 = binding.include.findViewById(R.id.image1);
        picture2 = binding.include.findViewById(R.id.image2);
        picture3 = binding.include.findViewById(R.id.image3);
        aSwitch = binding.include.findViewById(R.id.isFinish);
        start = binding.include.findViewById(R.id.button22);
        del1 = binding.include.findViewById(R.id.text1);
        del2 = binding.include.findViewById(R.id.text2);
        del3 = binding.include.findViewById(R.id.text3);
        viewModel.getAddressUtils().getAddress(address, getActivity());
        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PictureFileUtil.showAlbum(FilingPhthisisFragment.this, PictureConfig.CHOOSE_REQUEST);
            }
        });
        del1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tbPatientRecordDTO.setPicturePath1("");
                Utils.loadChatImage(getActivity(),getResources().getDrawable(R.drawable.no_image), picture1);
            }
        });
        del2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tbPatientRecordDTO.setPicturePath2("");
                Utils.loadChatImage(getActivity(),getResources().getDrawable(R.drawable.no_image), picture2);
            }
        });
        del3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tbPatientRecordDTO.setPicturePath3("");
                Utils.loadChatImage(getActivity(),getResources().getDrawable(R.drawable.no_image), picture3);
            }
        });

        aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b)
                    tbPatientRecordDTO.setIsFinish(1);
                else
                    tbPatientRecordDTO.setIsFinish(0);
            }
        });

        if (StringUtils.isNotNull(tbPatientRecordDTO.getPicturePath1()))
            Utils.loadChatImage(getActivity(),tbPatientRecordDTO.getPicturePath1(), picture1);
        if (StringUtils.isNotNull(tbPatientRecordDTO.getPicturePath2()))
            Utils.loadChatImage(getActivity(),tbPatientRecordDTO.getPicturePath2(), picture2);
        if (StringUtils.isNotNull(tbPatientRecordDTO.getPicturePath3()))
            Utils.loadChatImage(getActivity(),tbPatientRecordDTO.getPicturePath3(), picture3);
        if (StringUtils.isNotNull(tbPatientRecordDTO.getAddress())){
            address.setText(tbPatientRecordDTO.getAddress());
        } else{
            viewModel.getAddressUtils().getAddress(address, getActivity());
        }

        if (tbPatientRecordDTO.getIsFinish() == 0)
            aSwitch.setChecked(false);
        else
            aSwitch.setChecked(true);

    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == PictureConfig.CHOOSE_REQUEST) {
            // 图片选择结果回调
            tbPatientRecordDTO.setPicturePath1("");
            tbPatientRecordDTO.setPicturePath2("");
            tbPatientRecordDTO.setPicturePath3("");
            Utils.loadChatImage(getActivity(),getResources().getDrawable(R.drawable.no_image), picture1);
            Utils.loadChatImage(getActivity(),getResources().getDrawable(R.drawable.no_image), picture2);
            Utils.loadChatImage(getActivity(),getResources().getDrawable(R.drawable.no_image), picture3);

            List<LocalMedia> selectListPic = PictureSelector.obtainMultipleResult(data);
            tbPatientRecordDTO.setPicturePath1(selectListPic.size() > 0 ? selectListPic.get(0).getRealPath() : "");
            tbPatientRecordDTO.setPicturePath2(selectListPic.size() > 1 ? selectListPic.get(1).getRealPath() : "");
            tbPatientRecordDTO.setPicturePath3(selectListPic.size() > 2 ? selectListPic.get(2).getRealPath() : "");
            Utils.loadChatImage(getActivity(),tbPatientRecordDTO.getPicturePath1(), picture1);
            Utils.loadChatImage(getActivity(),tbPatientRecordDTO.getPicturePath2(), picture2);
            Utils.loadChatImage(getActivity(),tbPatientRecordDTO.getPicturePath3(), picture3);
        }
    }

    /**
     * 保存
     */
    private void save(){
        tbPatientRecordDTO.setChemotherapyRegimen(binding.editTextTextPersonName49.getText().toString());

        int checkedRadioButtonId = binding.radioGroupPlus08.getCheckedRadioButtonId();
        String cmWay = "";
        switch (checkedRadioButtonId){

            case R.id.radioButton65:
                cmWay = "1";
                break;
            case R.id.radioButton69:
                cmWay = "2";
                break;
            case R.id.radioButton67:
                cmWay = "3";
                break;
            case R.id.radioButton68:
                cmWay = "4";
                break;
        }
        tbPatientRecordDTO.setCmWay(cmWay);

        checkedRadioButtonId = binding.radioGroupPlus1111.getCheckedRadioButtonId();
        String diagnosticTyping = "";
        switch (checkedRadioButtonId){

            case R.id.radioButton39:
                diagnosticTyping = "1";
                break;
            case R.id.radioButton40:
                diagnosticTyping = "2";
                break;
            case R.id.radioButton41:
                diagnosticTyping = "3";
                break;
            case R.id.radioButton42:
                diagnosticTyping = "4";
                break;
            case R.id.radioButton43:
                diagnosticTyping = "5";
                break;
        }
        tbPatientRecordDTO.setDiagnosticTyping(diagnosticTyping);

        checkedRadioButtonId = binding.radioGroupPlus011.getCheckedRadioButtonId();
        String initialTreatment = "";
        switch (checkedRadioButtonId){

            case R.id.radioButton74:
                initialTreatment = "1";
                break;
            case R.id.radioButton75:
                initialTreatment = "2";
                break;
        }
        tbPatientRecordDTO.setInitialTreatment(initialTreatment);

        checkedRadioButtonId = binding.radioGroupPlus03.getCheckedRadioButtonId();
        String paymentMethod = "";
        switch (checkedRadioButtonId){

            case R.id.radioButton53:
                paymentMethod = "1";
                break;
            case R.id.radioButton54:
                paymentMethod = "2";
                break;
            case R.id.radioButton55:
                paymentMethod = "3";
                break;
        }
        tbPatientRecordDTO.setPaymentMethod(paymentMethod);

        checkedRadioButtonId = binding.radioGroupPlus07.getCheckedRadioButtonId();
        String reTreatment = "";
        switch (checkedRadioButtonId){

            case R.id.radioButton61:
                reTreatment = "1";
                break;
            case R.id.radioButton62:
                reTreatment = "2";
                break;
            case R.id.radioButton66:
                reTreatment = "3";
                break;
            case R.id.radioButton63:
                reTreatment = "4";
                break;
            case R.id.radioButton64:
                reTreatment = "5";
                break;
        }
        tbPatientRecordDTO.setReTreatment(reTreatment);

        tbPatientRecordDTO.setRecDate(binding.textView23.getText().toString());

        tbPatientRecordDTO.setRecNo(binding.textView24.getText().toString());

        tbPatientRecordDTO.setRecentTreatmentDate(binding.textView234.getText().toString());

        checkedRadioButtonId = binding.radioGroupPlus09.getCheckedRadioButtonId();
        String status = "";
        switch (checkedRadioButtonId){

            case R.id.radioButton71:
                status = "0";
                break;
            case R.id.radioButton70:
                status = "1";
                break;
        }
        tbPatientRecordDTO.setStatus(status);

        tbPatientRecordDTO.setTreatmentDate(binding.textView235.getText().toString());

        checkedRadioButtonId = binding.radioGroupPlus027.getCheckedRadioButtonId();
        String treatmentOrgType = "";
        switch (checkedRadioButtonId){

            case R.id.radioButton03:
                treatmentOrgType = "1";
                break;
            case R.id.radioButton04:
                treatmentOrgType = "2";
                break;
            case R.id.radioButton05:
                treatmentOrgType = "3";
                break;
        }
        tbPatientRecordDTO.setTreatmentOrgType(treatmentOrgType);

        tbPatientRecordDTO.setDiagnosisDate(binding.textView236.getText().toString());

        tbPatientRecordDTO.setDoctorID(viewModel.getUserInfo().getDId());

        tbPatientRecordDTO.setDoctorName(viewModel.getUserInfo().getDId());

        tbPatientRecordDTO.setPersonID(inhabitantDTO.getID());

        tbPatientRecordDTO.setPersonName(inhabitantDTO.getNAME());

    }

    private void setInhabitantView(){
        binding.textView177.setText(inhabitantDTO.getNAME());
        if ("1".equals(inhabitantDTO.getSEX()))
            binding.textView179.setText("男");
        else if ("2".equals(inhabitantDTO.getSEX()))
            binding.textView179.setText("女");
        binding.textView183.setText(inhabitantDTO.getTEL());
        binding.textView184.setText(inhabitantDTO.getIDCARD());
    }

    private void clearInhabitantView(){
        binding.textView177.setText("");
        binding.textView179.setText("");
        binding.textView183.setText("");
        binding.textView184.setText("");
        Utils.Toast(context,"未查到该身份证的信息，请同步居民信息后再添加！");
    }

    /**
     * 初始化数据
     */
    private void initData() {
        Bundle arguments = getArguments();

        if (arguments == null){
            tbPatientRecordDTO = new TbPatientRecordDTO();
        }
        else {
            tbPatientRecordDTO = (TbPatientRecordDTO) arguments.get("tbPatientRecordDTO");
            inhabitantDTO = viewModel.getInhabitantRepository().findByField("ID",tbPatientRecordDTO.getPersonID());
            if (inhabitantDTO == null){
                Utils.Toast(context,"请先更新病人数据！");
                hideAddFragment();
            }else {
                echo();
            }
        }
    }

    /**
     * 数据回显
     */
    private void echo() {
        setInhabitantView();

        //登记日期
        if (StringUtils.isNotNull(tbPatientRecordDTO.getRecDate()))
            binding.textView23.setText(tbPatientRecordDTO.getRecDate());

        //登记号
        if (StringUtils.isNotNull(tbPatientRecordDTO.getRecNo()))
            binding.textView24.setText(tbPatientRecordDTO.getRecNo());

        //确诊日期
        if (StringUtils.isNotNull(tbPatientRecordDTO.getDiagnosisDate()))
            binding.textView236.setText(tbPatientRecordDTO.getDiagnosisDate());

        //诊断分型
        if (StringUtils.isNotNull(tbPatientRecordDTO.getDiagnosticTyping())){
            switch (tbPatientRecordDTO.getDiagnosticTyping()){
                case "1":
                    binding.radioGroupPlus1111.check(R.id.radioButton39);
                    break;
                case "2":
                    binding.radioGroupPlus1111.check(R.id.radioButton40);
                    break;
                case "3":
                    binding.radioGroupPlus1111.check(R.id.radioButton41);
                    break;
                case "4":
                    binding.radioGroupPlus1111.check(R.id.radioButton42);
                    break;
                case "5":
                    binding.radioGroupPlus1111.check(R.id.radioButton43);
                    break;
            }
        }

        //处治
        if (StringUtils.isNotNull(tbPatientRecordDTO.getInitialTreatment())){
            switch (tbPatientRecordDTO.getInitialTreatment()){
                case "1":
                    binding.radioGroupPlus011.check(R.id.radioButton74);
                    break;
                case "2":
                    binding.radioGroupPlus011.check(R.id.radioButton75);
                    break;
            }
        }

        //复治
        if (StringUtils.isNotNull(tbPatientRecordDTO.getReTreatment())){
            switch (tbPatientRecordDTO.getReTreatment()){
                case "1":
                    binding.radioGroupPlus07.check(R.id.radioButton61);
                    break;
                case "2":
                    binding.radioGroupPlus07.check(R.id.radioButton62);
                    break;
                case "3":
                    binding.radioGroupPlus07.check(R.id.radioButton66);
                    break;
                case "4":
                    binding.radioGroupPlus07.check(R.id.radioButton63);
                    break;
                case "5":
                    binding.radioGroupPlus07.check(R.id.radioButton64);
                    break;
            }
        }

        //最近一次治疗单位
        if (StringUtils.isNotNull(tbPatientRecordDTO.getTreatmentOrgType())){
            switch (tbPatientRecordDTO.getTreatmentOrgType()){
                case "1":
                    binding.radioGroupPlus027.check(R.id.radioButton03);
                    break;
                case "2":
                    binding.radioGroupPlus027.check(R.id.radioButton04);
                    break;
                case "3":
                    binding.radioGroupPlus027.check(R.id.radioButton05);
                    break;
            }
        }

        //最近一次治疗日期
        if (StringUtils.isNotNull(tbPatientRecordDTO.getRecentTreatmentDate()))
            binding.textView234.setText(tbPatientRecordDTO.getRecentTreatmentDate());

        //本次化疗开始日期
        if (StringUtils.isNotNull(tbPatientRecordDTO.getTreatmentDate()))
            binding.textView235.setText(tbPatientRecordDTO.getTreatmentDate());

        //化疗方案
        if (StringUtils.isNotNull(tbPatientRecordDTO.getChemotherapyRegimen()))
            binding.editTextTextPersonName49.setText(tbPatientRecordDTO.getChemotherapyRegimen());

        //药费来源
        if (StringUtils.isNotNull(tbPatientRecordDTO.getPaymentMethod())){
            switch (tbPatientRecordDTO.getPaymentMethod()){
                case "1":
                    binding.radioGroupPlus03.check(R.id.radioButton53);
                    break;
                case "2":
                    binding.radioGroupPlus03.check(R.id.radioButton54);
                    break;
                case "3":
                    binding.radioGroupPlus03.check(R.id.radioButton55);
                    break;
            }
        }

        //化疗管理方式
        if (StringUtils.isNotNull(tbPatientRecordDTO.getCmWay())){
            switch (tbPatientRecordDTO.getCmWay()){
                case "1":
                    binding.radioGroupPlus08.check(R.id.radioButton65);
                    break;
                case "2":
                    binding.radioGroupPlus08.check(R.id.radioButton69);
                    break;
                case "3":
                    binding.radioGroupPlus08.check(R.id.radioButton67);
                    break;
                case "4":
                    binding.radioGroupPlus08.check(R.id.radioButton68);
                    break;
            }
        }

        //状态
        if (StringUtils.isNotNull(tbPatientRecordDTO.getStatus())){
            switch (tbPatientRecordDTO.getStatus()){
                case "0":
                    binding.radioGroupPlus09.check(R.id.radioButton71);
                    break;
                case "1":
                    binding.radioGroupPlus09.check(R.id.radioButton70);
                    break;
            }
        }

        if (StringUtils.isNotNull(tbPatientRecordDTO.getDoctorName()))
            binding.editTextTextPersonName58.setText(tbPatientRecordDTO.getDoctorName());

    }

    private void hideAddFragment() {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(0, R.anim.fragment_slide_down);
        ft.hide(this);
        ft.commitAllowingStateLoss();
    }
}
